import request from '@/axios'
import type {
  AdvertListParams,
  AdvertListResponse,
  AdvertDetailResponse,
  AdvertCreateOrUpdateParams
} from '../types'

// 获取广告列表
export const getAdvertPageList = (params: AdvertListParams): Promise<AdvertListResponse> => {
  return request.get({ url: '/advert/list', params }).then((res) => {
    return {
      code: res.code,
      message: res.message || '',
      data: res.data
    }
  })
}

// 获取广告详情
export const getAdvertDetail = (id: number): Promise<AdvertDetailResponse> => {
  return request.get({ url: `/advert/${id}` }).then((res) => {
    return {
      code: res.code,
      message: res.message || '',
      data: res.data
    }
  })
}

// 创建广告
export const createAdvert = (data: AdvertCreateOrUpdateParams): Promise<IResponse> => {
  return request.post({ url: '/advert/create', data })
}

// 更新广告
export const updateAdvert = (id: number, data: AdvertCreateOrUpdateParams): Promise<IResponse> => {
  return request.put({ url: `/advert/update/${id}`, data })
}

// 删除广告
export const deleteAdvert = (id: number): Promise<IResponse> => {
  return request.delete({ url: `/advert/delete/${id}` })
}
